<template>
  <div>
    <div class="table-operator" v-if="stage !== '05010' && stage !== '05050'">
<!--      <a-button v-permission="['10090']" type="primary" style="background-color: #67c23a; border: 0" @click="CreateNot">
        生成通知书
      </a-button>-->
      <template v-if="stage !== '01010' && stage !== '01020' && stage !== '01030'">
        <a-button :disabled="status == '9' || status == '2'" v-permission="['10090']" type="primary" @click="showConfirm">
          提交审核
        </a-button>
        <a-button :disabled="status !== '2'" v-permission="['10100']" @click="setApproveReason('9')"> 同意 </a-button>
        <a-button :disabled="status !== '2'" v-permission="['10100']" type="danger" @click="setApproveReason('1')">
          拒绝
        </a-button>
        <a-button @click="showShjl" style="margin-top:10px">审核记录</a-button>
      </template>
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      class="table_header_blue"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
      <span slot="actionName">
        <a-upload
          v-if="stage !== '05010' && stage !== '05050'"
          v-permission="['10090']"
          :data="fileData"
          name="files"
          :showUploadList="false"
          :multiple="false"
          :headers="tokenHeader"
          :action="url.upLoad"
          @change="handleImportExcel"
          accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
        >
          <a-button size="small" type="primary" icon="import">上传</a-button>
        </a-upload>
        <span v-else>操作</span>
      </span>
      <span slot="action" slot-scope="text, record" v-if="stage !== '05010' && stage !== '05050'">
        <a @click="OnPerview(record)">预览</a>
        <a-divider type="vertical" />
        <a @click="OnDownLoad(record)">下载</a>
        <a-divider type="vertical" />
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
          <a>删除</a>
        </a-popconfirm>
      </span>
      <span slot="action" slot-scope="text, record" v-else>
        <a @click="OnPerview(record)">预览</a>
        <a-divider type="vertical" />
        <a @click="OnDownLoad(record)">下载</a>
      </span>
    </a-table>
    <SelectApprove ref="approver" :id="id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <shjlModal ref="shjlModal" :id="id" :typeId="typeId" :apiUrl="url.applyLog"></shjlModal>
  </div>
</template>
<script>
import { filePerviewMixin } from '@/mixins/filePerviewMixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { butStatus } from '../public/butStatus'
import { getAction, httpAction } from '@/api/manage'
import columns from './indexColumns'
import SelectApprove from '../public/SelectApprover'
import SetReason from '../public/SetReason'
import shjlModal from '../shjlModal'
import { Base64 } from 'js-base64'

export default {
  name: 'sjtzs',
  mixins: [JeecgListMixin, filePerviewMixin, butStatus],
  props: ['id', 'stage', 'type'],
  components: {
    SetReason,
    SelectApprove,
    shjlModal,
  },
  data() {
    return {
      queryParam: {
        type: 'sjtzs',
        proId: this.id,
        stage: this.stage,
        typeId: this.type,
      },
      typeId: this.type,
      fileData: {
        biz: 'sjtzs',
        type: 'sjtzs',
        proId: this.id,
        ztfaId: '',
      },
      //表头
      columns: columns(this),
      url: {
        list: '/sjxmzygl/sjWorkWords/getTzsList',
        delete: '/sjxmzygl/sjWorkWords/delete',
        upLoad: `${window._CONFIG['domianURL']}/sys/common/sjTzsUpload`,
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        applyLog: '/sjxmzygl/sjWorkApplyLog/queryApplyLog',
      },
    }
  },
  created() {
    this.getFA()
  },
  methods: {
    CreateNot() {
      getAction('/sjxmzygl/sjWorkWords/generateAuditNotice', {
        proId: this.id,
        ztfaId: this.fileData.ztfaId,
      }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    getFA() {
      getAction('/sjxmzygl/sjWorkZtfa/list', { proId: this.id }).then((res) => {
        if (res.success) {
          let list = res.result.records || res.result
          if (list.length > 0) {
            this.fileData.ztfaId = list[0].id
          } else {
            this.fileData.ztfaId = null
          }
        }
      })
    },

    OnPerview(record) {
      let fileUrl = `${window._CONFIG['onlinePreviewFileURL']}/sys/common/static/${record.fileUrl}`
      // let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(fileUrl)}`
      let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(Base64.encode(fileUrl))}`
      window.open(url, '_blank')
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
.funBtn {
  padding: 0 10px;
  margin-left: 10px;
}
</style>